package com.taint.advice;



import com.taint.callgraph.CallRecorder;

import com.taint.logger.TraceEndpoint;
import com.taint.logger.TraceEntry;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.implementation.bytecode.assign.Assigner;

import static com.taint.logger.TraceEndpoint.SOURCEEXTI;


public class SourceMethodAdvice {

    @Advice.OnMethodEnter
    public static TraceEntry MethodBefore(@Advice.Origin("#t") String type, @Advice.Origin("#m") String method, @Advice.Origin("#d") String desc, @Advice.AllArguments Object[] args) {
        return CallRecorder.MethodBefore(TraceEndpoint.SOURCEENTRY,type, method, desc, args);
    }


    @Advice.OnMethodExit
    public static void MethodAfter(@Advice.Enter TraceEntry item, @Advice.Origin("#t") String type, @Advice.Origin("#m") String method, @Advice.Origin("#s") String sig, @Advice.Return(typing = Assigner.Typing.DYNAMIC, readOnly = false) Object returned) {
        //Logger.Log("source  exit: " + String.format("%s %s %s ", type, method, sig));
        // TaintLogger.info("source exit",String.format("%s %s %s returned: %s",type,method,sig, returned!=null?returned:null));

        CallRecorder.MethodAfter(SOURCEEXTI,item, returned);


    }


}
